package tt.com.financialmanagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import tt.com.common.model.Dead;
import tt.com.common.model.OrderProject;
import tt.com.common.model.YxCommonPurchase;
import tt.com.common.util.PageUtil;
import tt.com.financialmanagement.mapper.YxCommonPurchaseMapper;
import tt.com.financialmanagement.service.YxCommonPurchaseServe;

import java.util.List;

@Service
public class YxCommonPurchaseServeImpl extends ServiceImpl<YxCommonPurchaseMapper,YxCommonPurchase> implements YxCommonPurchaseServe {


    @Override
    public ResponseEntity selectByOrderId(OrderProject orderProject) {
        //判断是否有该项目下的采购单
        QueryWrapper<YxCommonPurchase> wrapper = new QueryWrapper<>();
        wrapper.eq("data_status",1);
        List<YxCommonPurchase> yxCommonPurchases = baseMapper.selectList(wrapper);
        if (yxCommonPurchases.size()<0){
            return new ResponseEntity("该项目没有采购信息", HttpStatus.INTERNAL_SERVER_ERROR);
        }
        PageUtil pageUtil=new PageUtil();
        IPage<YxCommonPurchase> page = new Page<>(pageUtil.getPageIndex(), pageUtil.getPageSize());
        QueryWrapper<YxCommonPurchase> qw=new QueryWrapper<>();
        qw.eq("organ_id",orderProject.getOrganId());
        qw.eq("data_status",1);
        IPage<YxCommonPurchase> page1 = baseMapper.selectPage(page, qw);
        pageUtil.setData(page1);
        //设计总数
        QueryWrapper<YxCommonPurchase> qwe=new QueryWrapper<>();
        qw.eq("data_status",1);
        pageUtil.setTotalSize(baseMapper.selectCount(qwe));
        //设置总页数
        pageUtil.setTotalPage(pageUtil.getPageSize()/pageUtil.getPageSize());
        return new  ResponseEntity(pageUtil,HttpStatus.OK);
    }
}
